package cn.itcast.bos.web.action.system;

import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.service.system.PermissionService;
import cn.itcast.bos.utils.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

@Namespace("/")
@ParentPackage("json-default")
@Scope("protoType")
@Controller
public class PermissionAction extends BaseAction<Permission>{
    @Autowired
    private PermissionService permissionService;
    //查询所有的方法
    @Action(value = "permission_findAll",results = {@Result(name="success",type = "json")})
    public String findAll(){
        List<Permission> permissions = permissionService.findAll();
        ActionContext.getContext().getValueStack().push(permissions);
        return SUCCESS;
    }
    //保存权限的方法
    @Action(value="permission_save",results = {@Result(name="success",type="redirect",location = "./pages/system/permission.html")})
    public String savePermission(){
        permissionService.save(model);
        return SUCCESS;
    }
}
